//
//  LeoAlertView.m
//  leo
//
//  Created by 常艳 on 15/9/13.
//  Copyright (c) 2015年 mdx. All rights reserved.
//

#import "LeoAlertView.h"

@implementation LeoAlertView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/



@synthesize backgroundview;
@synthesize alertview;
@synthesize contentLabel;
@synthesize confirmButton;
@synthesize cancelButton;

@synthesize contentString;

@synthesize backgroundButton;
@synthesize originalView;
@synthesize inputTextField;
@synthesize motherLabel;

static float littleButtonHeight;
static float alertViewWidth;
static float alertViewHeight;
static float contentLabelHeight;



/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */


-(LeoAlertView*) initWithContentString:(NSString *)message
{
    
    [self setup];
    contentString=[NSString stringWithFormat:@"%@",message];
    [self makeMessage:contentString];
    
    return self;
    
}
-(LeoAlertView*) initStyle_2WithContentString:(NSString *)message
{
    
    NSLog(@"te");
    UIView *backgroundView = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] keyWindow].frame];
    backgroundView.backgroundColor = [UIColor blackColor];
    backgroundView.alpha = 0.4;
    
    [self addSubview:backgroundView];
    
    [self makeAlertView_2];
    
    [self addSubview:alertview];
    
    [self makeMessage:message];
    
    return self;
    
}


-(LeoAlertView*) initForStyle_3
{
    
    UIView *backgroundView = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] keyWindow].frame];
    backgroundView.backgroundColor = [UIColor blackColor];
    backgroundView.alpha = 0.4;
    
    [self addSubview:backgroundView];
    
    [self makeAlertView_3];
    
    [self addSubview:alertview];
    
    return self;
    
}

- (void)setup {
    
    UIView *backgroundView = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] keyWindow].frame];
    backgroundView.backgroundColor = [UIColor blackColor];
    backgroundView.alpha = 0.4;
    
    [self addSubview:backgroundView];
    
    [self makeAlertView_1];
    
    [self addSubview:alertview];
    
}

-(void) deleteMe
{
    [self resignKeyWindow];
    self.hidden = YES;
}


- (void)show {
    [self makeKeyWindow];
    [self makeKeyAndVisible];
    self.hidden = NO;
}


// 一个对话框带两个按钮Style
-(void)makeAlertView_1
{
    float width=[UIScreen mainScreen].bounds.size.width;
    float height=[UIScreen mainScreen].bounds.size.height;
    
    //    if (width==375)
    //    {
    alertViewWidth=500/2;
    alertViewHeight=250/2;
    littleButtonHeight=80/2;
    contentLabelHeight=40/2;
    //    }
    alertview=[[UIView alloc]initWithFrame:CGRectMake((width-alertViewWidth)/2, (height-alertViewHeight)/2, alertViewWidth, alertViewHeight)];
    //上边框
    UIImageView *upBoarderLabel=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, alertViewWidth, 3)];
    upBoarderLabel.backgroundColor=[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0];
    
    cancelButton=[[UIButton alloc]initWithFrame:CGRectMake(0, alertViewHeight-littleButtonHeight, alertViewWidth/2, littleButtonHeight)];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton setTitleColor:[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0] forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(deleteMe) forControlEvents:UIControlEventTouchDown];
    
    
    
    confirmButton=[[UIButton alloc]initWithFrame:CGRectMake(alertViewWidth/2, alertViewHeight-littleButtonHeight, alertViewWidth/2, littleButtonHeight)];
    [confirmButton setTitle:@"确认" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(deleteMe) forControlEvents:UIControlEventTouchDown];
    
    
    UILabel *line_1=[[UILabel alloc]initWithFrame:CGRectMake(0, alertViewHeight-littleButtonHeight, alertViewWidth, 1)];
    line_1.layer.borderColor = [UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1.0].CGColor;
    line_1.layer.borderWidth = 1.0;
    
    UILabel *line_2=[[UILabel alloc]initWithFrame:CGRectMake(alertViewWidth/2 , alertViewHeight-littleButtonHeight, 1, littleButtonHeight)];
    line_2.layer.borderColor = [UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1.0].CGColor;
    line_2.layer.borderWidth = 1.0;
    
    contentLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, (alertViewHeight-littleButtonHeight-contentLabelHeight)/2, alertViewWidth, contentLabelHeight)];
    contentLabel.textAlignment=NSTextAlignmentCenter;
    
    [alertview addSubview:upBoarderLabel];
    [alertview addSubview:confirmButton];
    [alertview addSubview:cancelButton];
    [alertview addSubview:contentLabel];
    [alertview addSubview:line_1];
    [alertview addSubview:line_2];
    
    alertview.backgroundColor=[UIColor whiteColor];
    
}

//一个对话框带一个按钮风格
-(void)makeAlertView_2
{
    float width=[UIScreen mainScreen].bounds.size.width;
    float height=[UIScreen mainScreen].bounds.size.height;
    
    //    if (width==375)
    //    {
    alertViewWidth=500/2;
    alertViewHeight=250/2;
    littleButtonHeight=80/2;
    contentLabelHeight=40/2;
    //}
    alertview=[[UIView alloc]initWithFrame:CGRectMake((width-alertViewWidth)/2, (height-alertViewHeight)/2, alertViewWidth, alertViewHeight)];
    //上边框
    UIImageView *upBoarderLabel=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, alertViewWidth, 3)];
    upBoarderLabel.backgroundColor=[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0];
    
    //    cancelButton=[[UIButton alloc]initWithFrame:CGRectMake(0, alertViewHeight-littleButtonHeight, alertViewWidth/2, littleButtonHeight)];
    //    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    //    [cancelButton setTitleColor:[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0] forState:UIControlStateNormal];
    //    [cancelButton addTarget:self action:@selector(deleteMe) forControlEvents:UIControlEventTouchDown];
    
    
    
    confirmButton=[[UIButton alloc]initWithFrame:CGRectMake(0,alertViewHeight-littleButtonHeight, alertViewWidth, littleButtonHeight)];
    [confirmButton setTitle:@"确认" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(deleteMe) forControlEvents:UIControlEventTouchDown];
    
    
    UILabel *line_1=[[UILabel alloc]initWithFrame:CGRectMake(0, alertViewHeight-littleButtonHeight, alertViewWidth, 1)];
    line_1.layer.borderColor = [UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1.0].CGColor;
    line_1.layer.borderWidth = 1.0;
    
    UILabel *line_2=[[UILabel alloc]initWithFrame:CGRectMake(alertViewWidth/2 , alertViewHeight-littleButtonHeight, 1, littleButtonHeight)];
    line_2.layer.borderColor = [UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1.0].CGColor;
    line_2.layer.borderWidth = 1.0;
    
    contentLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, (alertViewHeight-littleButtonHeight-contentLabelHeight)/2, alertViewWidth, contentLabelHeight)];
    contentLabel.textAlignment=NSTextAlignmentCenter;
    
    
    [alertview addSubview:upBoarderLabel];
    [alertview addSubview:confirmButton];
    // [alertview addSubview:cancelButton];
    [alertview addSubview:contentLabel];
    [alertview addSubview:line_1];
    // [alertview addSubview:line_2];
    
    alertview.backgroundColor=[UIColor whiteColor];
    
}
//一个对话框带一个textField及两个按钮功能
-(void)makeAlertView_3
{
    float width=[UIScreen mainScreen].bounds.size.width;
    float height=[UIScreen mainScreen].bounds.size.height;
    
    //    if (width==375)
    //    {
    alertViewWidth=500/2;
    alertViewHeight=250/2;
    littleButtonHeight=80/2;
    contentLabelHeight=40/2;
    //    }
    alertview=[[UIView alloc]initWithFrame:CGRectMake((width-alertViewWidth)/2, (height-alertViewHeight)/2, alertViewWidth, alertViewHeight)];
    //上边框
    UIImageView *upBoarderLabel=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, alertViewWidth, 3)];
    upBoarderLabel.backgroundColor=[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0];
    
    cancelButton=[[UIButton alloc]initWithFrame:CGRectMake(0, alertViewHeight-littleButtonHeight, alertViewWidth/2, littleButtonHeight)];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton setTitleColor:[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0] forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(deleteMe) forControlEvents:UIControlEventTouchDown];
    
    
    
    confirmButton=[[UIButton alloc]initWithFrame:CGRectMake(alertViewWidth/2, alertViewHeight-littleButtonHeight, alertViewWidth/2, littleButtonHeight)];
    [confirmButton setTitle:@"确认" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(amendNameAction) forControlEvents:UIControlEventTouchDown];
    
    
    UILabel *line_1=[[UILabel alloc]initWithFrame:CGRectMake(0, alertViewHeight-littleButtonHeight, alertViewWidth, 1)];
    line_1.layer.borderColor = [UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1.0].CGColor;
    line_1.layer.borderWidth = 1.0;
    
    UILabel *line_2=[[UILabel alloc]initWithFrame:CGRectMake(alertViewWidth/2 , alertViewHeight-littleButtonHeight, 1, littleButtonHeight)];
    line_2.layer.borderColor = [UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1.0].CGColor;
    line_2.layer.borderWidth = 1.0;
    
    
    float d=20;//**左右间距
    float c=10;//**上下
    inputTextField =[[UITextField alloc]initWithFrame:CGRectMake(0+d, (alertViewHeight-littleButtonHeight-contentLabelHeight)/2+c, alertViewWidth-2*d, contentLabelHeight)];
    inputTextField.layer.borderColor= [UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1.0].CGColor;
    inputTextField.layer.borderWidth = 1.0;
    
    
    
    float v=5;//上下间距
    UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0+d, (alertViewHeight-littleButtonHeight-contentLabelHeight)/2-contentLabelHeight-v, alertViewWidth-d, contentLabelHeight)];
    
    titleLabel.text=@"修改昵称";
    titleLabel.textColor=[UIColor colorWithRed:192/255.0 green:178/255.0 blue:134/255.0 alpha:1.0];
    //inputTextField.textAlignment=NSTextAlignmentCenter;
    
    [alertview addSubview:upBoarderLabel];
    [alertview addSubview:confirmButton];
    [alertview addSubview:cancelButton];
    [alertview addSubview:inputTextField];
    [alertview addSubview:titleLabel];
    [alertview addSubview:line_1];
    [alertview addSubview:line_2];
    
    alertview.backgroundColor=[UIColor whiteColor];
    
}



-(void)makeMessage:(NSString*)message
{
    contentLabel.text=message;
}

@end
